package com.tanhua.server.controller;

import com.tanhua.model.vo.PageResult;
import com.tanhua.model.vo.SettingsVo;
import com.tanhua.server.service.SettingsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
@RequestMapping("/users")
public class SettingsController {
    @Autowired
    private SettingsService settingsService;

    /*查询通用设置*/
    @GetMapping("/settings")
    public ResponseEntity<Object> selectAllSettings() {
        SettingsVo settingsVo = settingsService.selectAllSettings();
        return ResponseEntity.ok(settingsVo);
    }

    /*通知设置*/
    @PostMapping("/notifications/setting")
    public ResponseEntity<Object> notifications(@RequestBody Map map) {
        settingsService.saveSettings(map);
        return ResponseEntity.ok("ok");
    }

    /*分页查询黑名单列表*/
    @GetMapping("/blacklist")
    public ResponseEntity<Object> blackList(@RequestParam(defaultValue = "1") int page,
                                    @RequestParam(defaultValue = "10") int size) {
        //调用service查询
        PageResult pr = settingsService.blackList(page, size);
        return ResponseEntity.ok(pr);
    }

    /*取消用户黑名单*/
    @DeleteMapping("/blacklist/{uid}")
    public ResponseEntity<Object> deleteBlackList(@PathVariable("uid") Long deleteId) {
        settingsService.deleteBlackList(deleteId);
        return ResponseEntity.ok("ok");
    }

    /*设置陌生人问题*/
    @PostMapping("/questions")
    public ResponseEntity<Object> questions(@RequestBody Map map) {
        //获取参数
        String content = (String) map.get("content");
        settingsService.saveQuestion(content);
        return ResponseEntity.ok("ok");
    }
}
